<template>
  <div class="_wz_cent_main _wz_exam">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="100" inline>
        <FormItem label="试卷名称">
          <i-input v-model="formDataSearch.materialName" placeholder="试卷名称" clearable />
        </FormItem>
        <FormItem label="试卷方向">
          <i-select v-model="formDataSearch.materialDirection" filterable placeholder="试卷方向" clearable>
            <Option v-for="item in optionsData" :value="item.code" :key="item.code">{{ item.value }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="试卷类型" v-if="searchType">
          <i-select v-model="formDataSearch.materialTrainType" filterable placeholder="请选择试卷类型" clearable>
            <Option v-for="item in transportationData" :value="item.code" :key="item.code">{{ item.value }}</Option>
          </i-select>
        </FormItem>
        <FormItem label="审核状态" v-if="searchType">
          <i-select v-model="formDataSearch.materialType" filterable placeholder="审核状态" clearable>
            <Option value="0">审核中</Option>
            <Option value="1">审核通过</Option>
            <Option value="-1">未通过</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">
        列表
        <span style="color: #ed4014;margin: 0 0 0 10px;font-weight: 600;font-size: 12px;">审核素材时间为：9:00-18:00；如使用授权课件，请联系商务人员。</span>
      </p>
      <!--内部的-->
      <p slot="extra">
        <Button type="primary" @click="addTableData">添加</Button>
      </p>

      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>
    <Drawer :title="formTitle" v-model="formOperation" width="700" :draggable="true" :mask-closable="false" :styles="formOperationStyles">
      <addPaper v-if="formOperation" :selectData="selectData" @closeFun="closeFun"></addPaper>
    </Drawer>

    <Drawer v-model="modal" title="课件查看" width="700" :draggable="true">
      <materialExam v-if="modal" :materialData="materialData"></materialExam>
    </Drawer>


    <Modal v-model="qureyOverruleReasonType" title="驳回原由" :footer-hide="true">
      <Timeline>
        <TimelineItem v-for="item in qureyOverruleReason" :key="item.id">
          <p class="time">{{item.createTime}}</p>
          <p class="content">{{item.materialAuditOverruleReason}}</p>
        </TimelineItem>
      </Timeline>
    </Modal>
    <Spin size="large" fix v-if="spinShow"></Spin>


  </div>
</template>
<script>

  import addPaper from '../ExamTest/addPaper.vue'
  import materialExam from '../public/materialExam.vue'
  import wzTbale from "../../../components/table/table";

  export default {
    components: {
      addPaper,//添加试卷
      materialExam,//试题
      wzTbale,//列表
    },
    data() {
      return {
        spinShow:false,//本页加载
        searchType:false,//搜索条件
        transportationData: [],//运输类型
        formDataSearch: {
          materialOpen:0
        },//搜索表单数据

        formOperation: false,//表单左侧移出
        formOperationStyles: {//表单左侧移出css
          height: 'calc(100% - 55px)',
          overflow: 'auto',
          paddingBottom: '53px',
          position: 'static'
        },
        formTitle: "",//表单名称


        qureyOverruleReason: [],//驳回原因list
        qureyOverruleReasonType: false,//驳回弹出


        selectData: {},//选择数据
        //试卷
        modal: false,//弹出层状态
        materialData: {},
        optionsData: [],//考试方向数据

        tableData: {
          url: this.apiUrl.webApi + "/educate/materialExam/materialExamPageList",//请求地址
          method: 'post',//请求方式
          where: {materialOpen:0},//搜索条件
          height: 'auto',//表格高度 auto
          page: true,//分页是否使用
          columns: [//表头数据
            {type: 'index', width: 70, align: 'center', title: '序号'},
            {title: '试卷名称', minWidth: 200, key: 'materialExamName'},
            {title: '试卷类型', minWidth: 100, key: 'materialExamTransportTypeName'},
            {title: '试卷方向', minWidth: 100, key: 'materialExamDirectionName'},
            {
              title: '考题数量', minWidth: 100, render: (h, params) => {
                return h('span', params.row.materialExamAmount + '-题');
              }
            },
            {
              title: '考题总分', minWidth: 100, render: (h, params) => {
                return h('span', params.row.materialExamTotalScore + '分');
              }
            },
            {
              title: '及格率', minWidth: 100, render: (h, params) => {
                return h('span', (params.row.materialExamPassRate * 100) + '%');
              }
            },
            {
              title: '及格分数', minWidth: 100, render: (h, params) => {
                return h('span', params.row.materialExamPassScore + '分');
              }
            },
            {title: '上传时间', minWidth: 150, key: 'createTime'},

            {
              title: '审核状态', minWidth: 140, render: (h, params) => {
                //  0：审核中，1：通过，-1：未通过
                var test = '';
                if (params.row.materialExamAudit == 1) {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'success'
                    }
                  }, '审核通过')
                } else if (params.row.materialExamAudit == 0) {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'warning'
                    }
                  }, '审核中')
                } else {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'error'
                    }
                  }, '审核驳回')
                }
                return test;
              }
            },
            {
              title: '处理状态', minWidth: 140, render: (h, params) => {
                //  0：审核中，1：通过，-1：未通过
                var test = '';
                if (params.row.materialExamProcess == 1) {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'success'
                    }
                  }, '处理通过')
                } else if (params.row.materialExamProcess == 0) {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'warning'
                    }
                  }, '处理中')
                } else {
                  test = h('Tag', {
                    props: {
                      type: 'dot',
                      color: 'error'
                    }
                  }, '处理失败')
                }
                return test;
              }
            },
            {title: '运输企业', minWidth: 260, key: 'deptName'},
            {
              title: '操作', fixed: 'right', width: 120,
              render: (h, params) => {
                let operationButtons = [];
                if (params.row.materialExamProcess == 1) {//处理完成
                  operationButtons.push(h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.materialData.id = params.row.uuid
                        this.modal = true;
                      }
                    }
                  }, '查看'))
                }else{
                  //修改
                  operationButtons.push(h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.formTitle = "修改";
                        this.selectData = JSON.parse(JSON.stringify(params.row));
                        this.formOperation = true;
                      }
                    }
                  }, '修改'))


                  //删除
                  operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                  operationButtons.push(h('span', {
                    style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.removeTableFun(params.row)
                      }
                    }
                  }, '删除'))
                }

                return operationButtons;
              }
            }
          ],
          format: {//返回数据格式
            list: ['data'],//数据list
            count: ['count'],//数据总量
          },
        },
      }
    },
    beforeCreate() {//beforeCreate创建前状态

    },
    created() {//created创建完毕状态
    },
    beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

    },
    mounted() {//mounted 挂载结束状态
      let that = this;

      //加载方向
      that.axios.post(that.apiUrl.systemDictSystemDictList,{type:'training_direction'}).then(res => {
        if (!!res) {
          that.optionsData = res.data.data
        }
      }).catch(err => {
        console.log('失败', err);
      })

      //企业类型
      that.axios.post(that.apiUrl.systemDictSystemDictList,{type:'transport_type'}).then(res => {
        if (!!res) {
          that.transportationData = res.data.data;
        }
      }).catch(err => {
        console.log('失败', err);
      })
    },
    methods: {//执行的方法
      //搜索
      searchSubmit() {
        this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
        this.$refs.wzTbale.tableLoadData(true);
      },
      //关闭 弹出框刷新列表
      closeFun(data) {
        if (data) {//添加修改 刷新表单
          this.$refs.wzTbale.tableLoadData();
        }
        this.formOperation = false;
      },
      //试卷添加
      addTableData() {
        let that = this;
        that.formTitle = "添加";
        that.selectData = {};
        that.formOperation = true;
      },
      //试卷删除
      removeTableFun(data) {//上面按钮删除   和   table里面删除 公用一个方法
        let that = this;
        that.$Modal.confirm({
          title: '删除提醒',
          content: '确定要删除选中的试卷？',
          onOk: () => {
            that.spinShow = true;//显示加载
            that.axios.post(that.apiUrl.webApi + "/educate/materialExam/materialExamDelete",{materialUuid:data.uuid}).then(res => {
              that.spinShow = false;
              if (!!res) {
                that.$Message.success('删除成功');
                that.$refs.wzTbale.tableLoadData();
              }
            }).catch(err => {
              console.log('失败', err);
            })
          },
          onCancel: () => {
            //点击取消
          }
        });
      },
    },
    watch: {//监听

    },
    beforeUpdate() {//beforeUpdate 更新前状态

    },
    updated() {//updated 更新完成状态

    },
    beforeDestroy() {//beforeDestroy 销毁前状态

    },
    destroyed() {//destroyed 销毁完成状态

    }
  }
</script>
<style lang="less">
  ._wz_exam {
    height: 100%;
    display: flex;
    flex-direction: column;


  }

</style>
